﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dev101.Models
{
    // A personal development plan consists of a collection of items that has:
    // - a priority, 
    // - a technology, 
    // - a mechanism for delivering the training experience, 
    // - the title of the training experience (book or video title), 
    // - a duration (length) in hours or pages, 
    // - a duration type indicating hours or pages, 
    // - a sub priority and a progress.   
    public class DevelopmentPlan
    {
        private double overallProgress;
        public List<Book> Books { get; set; }
        public List<Video> Videos { get; set; }
        public double OverallProgress 
        {
            get { return overallProgress; } 
            private set {
                double expectedDuration = 0;
                double actualDuration = 0;
                if(Books != null)
                {
                    expectedDuration += Books.Select(b => b.Duration.ExpectedDuration).Sum();
                    actualDuration += Books.Select(b => b.Duration.CurrentDuration).Sum();
                }
                if(Videos != null)
                {
                    expectedDuration += Videos.Select(b => b.Duration.ExpectedDuration.Ticks).Sum();
                    actualDuration += Videos.Select(b => b.Duration.CurrentDuration.Ticks).Sum();
                }
                if(actualDuration > 0)
                {
                    overallProgress = actualDuration / expectedDuration;
                }
            } 
        }
    }
    public class TrainingExperience<T>
    {
        public Guid TrainingExperienceKey { get; set; }
        public decimal PriorityWeighting { get; set; }
        public TechnologyArea TechnologyArea { get; set; }
        public Mechanism Mechanism { get; set; }
        public string Title { get; set; }
        public Duration<T> Duration { get; set; }
        public decimal SubPriority { get; set; }
        public virtual double Progress { get; set; }
    }
    public class TechnologyArea
    {
        public Guid TechnologyAreaKey { get; set; }
        public string TechnologyAreaDescription { get; set; }
    }
    public class Mechanism
    {
        public Guid MechanismKey { get; set; }
        public string MechanismType { get; set; }
        public string MechanismDescription { get; set; }
    }
    public class Duration<T>
    {
        public Guid DurationMeasureKey { get; set; }
        public T CurrentDuration { get; set; }
        public T ExpectedDuration { get; set; }
    }
    public class Book:TrainingExperience<int>
    {
        public override double Progress
        {
            get
            {
                return base.Progress;
            }
            set
            {
                if(Duration != null)
                {
                    if (Duration.ExpectedDuration > 0)
                        value = Duration.CurrentDuration / Duration.ExpectedDuration * 100;
                }
            }
        }
    }
    public class Video:TrainingExperience<TimeSpan>
    {
        public override double Progress
        {
            get
            {
                return base.Progress;
            }
            set
            {
                if (Duration != null)
                {
                    if (Duration.CurrentDuration.Ticks > 0)
                        base.Progress = Duration.CurrentDuration.Ticks / (double) Duration.ExpectedDuration.Ticks;
                }
            }
        }
    }
}
